package cn.iocoder.yudao.module.iot.gateway.protocol.custom.xiaoan.tcp.router.handler;

import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.router.handler.BaseProtocolHandler;
import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.router.handler.ProtocolHandler;
import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetSocket;
import lombok.extern.slf4j.Slf4j;

import static cn.iocoder.yudao.module.iot.gateway.protocol.tcp.router.IotTcpUpstreamHandler.AUTH_METHOD;

/**
 * 协议处理器基类，提供公共方法
 */
@Slf4j
public abstract class XiaoAnBaseProtocolHandler extends BaseProtocolHandler {



    protected void sendResponse(IotDeviceMessageService iotDeviceMessageService,NetSocket socket, String requestId, String method, Object responseData, String codecType) {
        try {
            IotDeviceMessage responseMessage = IotDeviceMessage.replyOf(requestId, method, responseData,
                    null, null);
            byte[] encodedData = iotDeviceMessageService.encodeDeviceMessage(responseMessage, codecType);
            socket.write(Buffer.buffer(encodedData));
        } catch (Exception e) {
            log.error("[sendResponse][发送响应失败，requestId: {}]", requestId, e);
        }
    }




}
